Section 5 - Restricted Boltzmann Machine


In [ ]:

Implementation


In [1]:
import tensorflow as tf
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.utils import shuffle


c:\programdata\anaconda3\lib\site-packages\h5py\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.
  from ._conv import register_converters as _register_converters

In [2]:
class RBM(object):
    def __init__(self, D, M, an_id):
        self.D = D
        self.M = M
        self.id = an_id
        self.build(D, M)

    def set_session(self, session):
        self.session = session

    def build(self, D, M):
        # params
        self.W = tf.Variable(tf.random_normal(shape=(D, M)) * np.sqrt(2.0 / M))
        # note: without limiting variance, you get numerical stability issues
        self.c = tf.Variable(np.zeros(M).astype(np.float32))
        self.b = tf.Variable(np.zeros(D).astype(np.float32))

        # data
        self.X_in = tf.placeholder(tf.float32, shape=(None, D))

        # conditional probabilities
        # NOTE: tf.contrib.distributions.Bernoulli API has changed in Tensorflow v1.2
        V = self.X_in
        p_h_given_v = tf.nn.sigmoid(tf.matmul(V, self.W) + self.c)
        self.p_h_given_v = p_h_given_v # save for later
        
        r = tf.random_uniform(shape=tf.shape(p_h_given_v))
        H = tf.to_float(r < p_h_given_v)

        p_v_given_h = tf.nn.sigmoid(tf.matmul(H, tf.transpose(self.W)) + self.b)
        
        r = tf.random_uniform(shape=tf.shape(p_v_given_h))
        X_sample = tf.to_float(r < p_v_given_h)


        # build the objective
        objective = tf.reduce_mean(self.free_energy(self.X_in)) - tf.reduce_mean(self.free_energy(X_sample))
        self.train_op = tf.train.AdamOptimizer(1e-2).minimize(objective)
        

        # build the cost
        # we won't use this to optimize the model parameters
        # just to observe what happens during training
        logits = self.forward_logits(self.X_in)
        self.cost = tf.reduce_mean(
            tf.nn.sigmoid_cross_entropy_with_logits(
                labels=self.X_in,
                logits=logits,
            )
        )

    def fit(self, X, epochs = 1, batch_sz = 100, show_fig = False):
        N, D = X.shape
        n_batches = N // batch_sz

        costs = []
        
        for i in range(epochs):
            print("Epoch: ", i)
            X = shuffle(X)
            for j in range(n_batches):
                batch = X[j * batch_sz : (j * batch_sz + batch_sz)]
                _, c = self.session.run((self.train_op, self.cost), 
                                        feed_dict = {self.X_in: batch})
                if j % 10 == 0:
                    print("j / n_batches:", j, "/", n_batches, "cost: ", c)
                costs.append(c)
        if show_fig:
            plt.figure(figsize = (14, 14))
            plt.plot(costs)
            plt.show()

    def free_energy(self, V):
        b = tf.reshape(self.b, (self.D, 1))
        first_term = -tf.matmul(V, b)
        first_term = tf.reshape(first_term, (-1,))

        second_term = -tf.reduce_sum(
            # tf.log(1 + tf.exp(tf.matmul(V, self.W) + self.c)),
            tf.nn.softplus(tf.matmul(V, self.W) + self.c),
            axis=1
        )

        return first_term + second_term

    def forward_hidden(self, X):
        return tf.nn.sigmoid(tf.matmul(X, self.W) + self.c)

    def forward_logits(self, X):
        Z = self.forward_hidden(X)
        return tf.matmul(Z, tf.transpose(self.W)) + self.b

    def forward_output(self, X):
        return tf.nn.sigmoid(self.forward_logits(X))

    def transform(self, X):
        # accepts and returns a real numpy array
        # unlike forward_hidden and forward_output
        # which deal with tensorflow variables
        return self.session.run(self.p_h_given_v, 
                                feed_dict = {self.X_in: X})

In [3]:
def getKaggleMNIST():
    train = pd.read_csv('./data/Section 2/train.csv').as_matrix().astype(np.float32)
    train = shuffle(train)

    Xtrain = train[:-1000, 1:] / 255
    Ytrain = train[:-1000, 0].astype(np.int32)

    Xtest  = train[-1000:, 1:] / 255
    Ytest  = train[-1000:, 0].astype(np.int32)
    return Xtrain, Ytrain, Xtest, Ytest

In [4]:
Xtrain, Ytrain, Xtest, Ytest = getKaggleMNIST()

Xtrain = Xtrain.astype(np.float32)
Xtest = Xtest.astype(np.float32)
_, D = Xtrain.shape
K = len(set(Ytrain))

In [5]:
rbm = RBM(D, 300, 0)
init_op = tf.global_variables_initializer()
with tf.Session() as session:
    session.run(init_op)
    rbm.set_session(session)
    rbm.fit(Xtrain,  
            epochs = 10,
            show_fig = True)


Epoch:  0
j / n_batches: 0 / 410 cost:  0.75114536
j / n_batches: 10 / 410 cost:  0.23542331
j / n_batches: 20 / 410 cost:  0.20533612
j / n_batches: 30 / 410 cost:  0.18643746
j / n_batches: 40 / 410 cost:  0.17147003
j / n_batches: 50 / 410 cost:  0.15969531
j / n_batches: 60 / 410 cost:  0.15469585
j / n_batches: 70 / 410 cost:  0.15457776
j / n_batches: 80 / 410 cost:  0.14040473
j / n_batches: 90 / 410 cost:  0.13518213
j / n_batches: 100 / 410 cost:  0.14109783
j / n_batches: 110 / 410 cost:  0.13563217
j / n_batches: 120 / 410 cost:  0.12635556
j / n_batches: 130 / 410 cost:  0.13126253
j / n_batches: 140 / 410 cost:  0.12190761
j / n_batches: 150 / 410 cost:  0.12472801
j / n_batches: 160 / 410 cost:  0.12154306
j / n_batches: 170 / 410 cost:  0.11368052
j / n_batches: 180 / 410 cost:  0.11742955
j / n_batches: 190 / 410 cost:  0.11605334
j / n_batches: 200 / 410 cost:  0.11216199
j / n_batches: 210 / 410 cost:  0.12190011
j / n_batches: 220 / 410 cost:  0.11172784
j / n_batches: 230 / 410 cost:  0.111857876
j / n_batches: 240 / 410 cost:  0.114634104
j / n_batches: 250 / 410 cost:  0.10419982
j / n_batches: 260 / 410 cost:  0.11179025
j / n_batches: 270 / 410 cost:  0.1121053
j / n_batches: 280 / 410 cost:  0.11095826
j / n_batches: 290 / 410 cost:  0.10404059
j / n_batches: 300 / 410 cost:  0.11096375
j / n_batches: 310 / 410 cost:  0.1104827
j / n_batches: 320 / 410 cost:  0.103157446
j / n_batches: 330 / 410 cost:  0.10929324
j / n_batches: 340 / 410 cost:  0.103496514
j / n_batches: 350 / 410 cost:  0.105410255
j / n_batches: 360 / 410 cost:  0.10936486
j / n_batches: 370 / 410 cost:  0.10578646
j / n_batches: 380 / 410 cost:  0.10653108
j / n_batches: 390 / 410 cost:  0.10639544
j / n_batches: 400 / 410 cost:  0.10022521
Epoch:  1
j / n_batches: 0 / 410 cost:  0.103862554
j / n_batches: 10 / 410 cost:  0.09945726
j / n_batches: 20 / 410 cost:  0.10167142
j / n_batches: 30 / 410 cost:  0.10378738
j / n_batches: 40 / 410 cost:  0.10064463
j / n_batches: 50 / 410 cost:  0.100742236
j / n_batches: 60 / 410 cost:  0.099752866
j / n_batches: 70 / 410 cost:  0.10113429
j / n_batches: 80 / 410 cost:  0.09893817
j / n_batches: 90 / 410 cost:  0.09456443
j / n_batches: 100 / 410 cost:  0.10009269
j / n_batches: 110 / 410 cost:  0.101268224
j / n_batches: 120 / 410 cost:  0.09635416
j / n_batches: 130 / 410 cost:  0.09999442
j / n_batches: 140 / 410 cost:  0.10115575
j / n_batches: 150 / 410 cost:  0.095477305
j / n_batches: 160 / 410 cost:  0.09578107
j / n_batches: 170 / 410 cost:  0.09688547
j / n_batches: 180 / 410 cost:  0.09627434
j / n_batches: 190 / 410 cost:  0.092557006
j / n_batches: 200 / 410 cost:  0.09285739
j / n_batches: 210 / 410 cost:  0.0952459
j / n_batches: 220 / 410 cost:  0.095942706
j / n_batches: 230 / 410 cost:  0.096853115
j / n_batches: 240 / 410 cost:  0.09450393
j / n_batches: 250 / 410 cost:  0.095134966
j / n_batches: 260 / 410 cost:  0.09698011
j / n_batches: 270 / 410 cost:  0.088736005
j / n_batches: 280 / 410 cost:  0.09328718
j / n_batches: 290 / 410 cost:  0.094005376
j / n_batches: 300 / 410 cost:  0.09731649
j / n_batches: 310 / 410 cost:  0.09159269
j / n_batches: 320 / 410 cost:  0.092140876
j / n_batches: 330 / 410 cost:  0.09489857
j / n_batches: 340 / 410 cost:  0.09304812
j / n_batches: 350 / 410 cost:  0.08614801
j / n_batches: 360 / 410 cost:  0.08894037
j / n_batches: 370 / 410 cost:  0.08898014
j / n_batches: 380 / 410 cost:  0.09077429
j / n_batches: 390 / 410 cost:  0.09110346
j / n_batches: 400 / 410 cost:  0.09033206
Epoch:  2
j / n_batches: 0 / 410 cost:  0.10116705
j / n_batches: 10 / 410 cost:  0.09270797
j / n_batches: 20 / 410 cost:  0.09188228
j / n_batches: 30 / 410 cost:  0.09309366
j / n_batches: 40 / 410 cost:  0.08979606
j / n_batches: 50 / 410 cost:  0.09187962
j / n_batches: 60 / 410 cost:  0.09185328
j / n_batches: 70 / 410 cost:  0.09510735
j / n_batches: 80 / 410 cost:  0.09071845
j / n_batches: 90 / 410 cost:  0.08927979
j / n_batches: 100 / 410 cost:  0.09154802
j / n_batches: 110 / 410 cost:  0.08830801
j / n_batches: 120 / 410 cost:  0.08687569
j / n_batches: 130 / 410 cost:  0.092744574
j / n_batches: 140 / 410 cost:  0.08974818
j / n_batches: 150 / 410 cost:  0.09148417
j / n_batches: 160 / 410 cost:  0.09177004
j / n_batches: 170 / 410 cost:  0.088025115
j / n_batches: 180 / 410 cost:  0.088027634
j / n_batches: 190 / 410 cost:  0.08948959
j / n_batches: 200 / 410 cost:  0.09357868
j / n_batches: 210 / 410 cost:  0.09087609
j / n_batches: 220 / 410 cost:  0.08929618
j / n_batches: 230 / 410 cost:  0.09713815
j / n_batches: 240 / 410 cost:  0.08944509
j / n_batches: 250 / 410 cost:  0.08758197
j / n_batches: 260 / 410 cost:  0.08911928
j / n_batches: 270 / 410 cost:  0.09003989
j / n_batches: 280 / 410 cost:  0.08893287
j / n_batches: 290 / 410 cost:  0.08685086
j / n_batches: 300 / 410 cost:  0.09185103
j / n_batches: 310 / 410 cost:  0.08835572
j / n_batches: 320 / 410 cost:  0.08988723
j / n_batches: 330 / 410 cost:  0.09153476
j / n_batches: 340 / 410 cost:  0.08953737
j / n_batches: 350 / 410 cost:  0.092274085
j / n_batches: 360 / 410 cost:  0.09027116
j / n_batches: 370 / 410 cost:  0.085720524
j / n_batches: 380 / 410 cost:  0.083506994
j / n_batches: 390 / 410 cost:  0.09022257
j / n_batches: 400 / 410 cost:  0.08868862
Epoch:  3
j / n_batches: 0 / 410 cost:  0.08893514
j / n_batches: 10 / 410 cost:  0.092731364
j / n_batches: 20 / 410 cost:  0.09271455
j / n_batches: 30 / 410 cost:  0.090106
j / n_batches: 40 / 410 cost:  0.089235544
j / n_batches: 50 / 410 cost:  0.08764011
j / n_batches: 60 / 410 cost:  0.08279312
j / n_batches: 70 / 410 cost:  0.08992463
j / n_batches: 80 / 410 cost:  0.08914796
j / n_batches: 90 / 410 cost:  0.091314495
j / n_batches: 100 / 410 cost:  0.086937085
j / n_batches: 110 / 410 cost:  0.08718486
j / n_batches: 120 / 410 cost:  0.086836144
j / n_batches: 130 / 410 cost:  0.085521005
j / n_batches: 140 / 410 cost:  0.09052203
j / n_batches: 150 / 410 cost:  0.08638355
j / n_batches: 160 / 410 cost:  0.08758397
j / n_batches: 170 / 410 cost:  0.08987275
j / n_batches: 180 / 410 cost:  0.08422814
j / n_batches: 190 / 410 cost:  0.088353
j / n_batches: 200 / 410 cost:  0.08736126
j / n_batches: 210 / 410 cost:  0.08884457
j / n_batches: 220 / 410 cost:  0.08717723
j / n_batches: 230 / 410 cost:  0.08713625
j / n_batches: 240 / 410 cost:  0.0871267
j / n_batches: 250 / 410 cost:  0.0880558
j / n_batches: 260 / 410 cost:  0.08395462
j / n_batches: 270 / 410 cost:  0.087074354
j / n_batches: 280 / 410 cost:  0.08992293
j / n_batches: 290 / 410 cost:  0.08407943
j / n_batches: 300 / 410 cost:  0.08751512
j / n_batches: 310 / 410 cost:  0.09092702
j / n_batches: 320 / 410 cost:  0.08542287
j / n_batches: 330 / 410 cost:  0.08064138
j / n_batches: 340 / 410 cost:  0.08760119
j / n_batches: 350 / 410 cost:  0.08873016
j / n_batches: 360 / 410 cost:  0.08643844
j / n_batches: 370 / 410 cost:  0.08820698
j / n_batches: 380 / 410 cost:  0.08642502
j / n_batches: 390 / 410 cost:  0.09132501
j / n_batches: 400 / 410 cost:  0.090248264
Epoch:  4
j / n_batches: 0 / 410 cost:  0.08590438
j / n_batches: 10 / 410 cost:  0.08664724
j / n_batches: 20 / 410 cost:  0.09182104
j / n_batches: 30 / 410 cost:  0.08216093
j / n_batches: 40 / 410 cost:  0.088673234
j / n_batches: 50 / 410 cost:  0.08442565
j / n_batches: 60 / 410 cost:  0.087783374
j / n_batches: 70 / 410 cost:  0.08716681
j / n_batches: 80 / 410 cost:  0.083509475
j / n_batches: 90 / 410 cost:  0.0874232
j / n_batches: 100 / 410 cost:  0.08572045
j / n_batches: 110 / 410 cost:  0.08522357
j / n_batches: 120 / 410 cost:  0.08459
j / n_batches: 130 / 410 cost:  0.08693129
j / n_batches: 140 / 410 cost:  0.086597055
j / n_batches: 150 / 410 cost:  0.09019743
j / n_batches: 160 / 410 cost:  0.08774743
j / n_batches: 170 / 410 cost:  0.086107425
j / n_batches: 180 / 410 cost:  0.09153182
j / n_batches: 190 / 410 cost:  0.083358236
j / n_batches: 200 / 410 cost:  0.08490108
j / n_batches: 210 / 410 cost:  0.08217763
j / n_batches: 220 / 410 cost:  0.087557375
j / n_batches: 230 / 410 cost:  0.08648348
j / n_batches: 240 / 410 cost:  0.08712505
j / n_batches: 250 / 410 cost:  0.086223744
j / n_batches: 260 / 410 cost:  0.08638642
j / n_batches: 270 / 410 cost:  0.083912276
j / n_batches: 280 / 410 cost:  0.08685208
j / n_batches: 290 / 410 cost:  0.08448833
j / n_batches: 300 / 410 cost:  0.08855576
j / n_batches: 310 / 410 cost:  0.09013541
j / n_batches: 320 / 410 cost:  0.084568545
j / n_batches: 330 / 410 cost:  0.08576842
j / n_batches: 340 / 410 cost:  0.08140098
j / n_batches: 350 / 410 cost:  0.08627021
j / n_batches: 360 / 410 cost:  0.08734494
j / n_batches: 370 / 410 cost:  0.09090438
j / n_batches: 380 / 410 cost:  0.08374458
j / n_batches: 390 / 410 cost:  0.08395884
j / n_batches: 400 / 410 cost:  0.086009696
Epoch:  5
j / n_batches: 0 / 410 cost:  0.08545354
j / n_batches: 10 / 410 cost:  0.08118835
j / n_batches: 20 / 410 cost:  0.08287444
j / n_batches: 30 / 410 cost:  0.08412861
j / n_batches: 40 / 410 cost:  0.08167741
j / n_batches: 50 / 410 cost:  0.08489629
j / n_batches: 60 / 410 cost:  0.079287924
j / n_batches: 70 / 410 cost:  0.08457559
j / n_batches: 80 / 410 cost:  0.08790238
j / n_batches: 90 / 410 cost:  0.08871362
j / n_batches: 100 / 410 cost:  0.08503748
j / n_batches: 110 / 410 cost:  0.08525437
j / n_batches: 120 / 410 cost:  0.088047005
j / n_batches: 130 / 410 cost:  0.088409886
j / n_batches: 140 / 410 cost:  0.087518774
j / n_batches: 150 / 410 cost:  0.08323532
j / n_batches: 160 / 410 cost:  0.08669902
j / n_batches: 170 / 410 cost:  0.08757917
j / n_batches: 180 / 410 cost:  0.08432257
j / n_batches: 190 / 410 cost:  0.086919844
j / n_batches: 200 / 410 cost:  0.08498356
j / n_batches: 210 / 410 cost:  0.085011244
j / n_batches: 220 / 410 cost:  0.0850136
j / n_batches: 230 / 410 cost:  0.08707948
j / n_batches: 240 / 410 cost:  0.08966181
j / n_batches: 250 / 410 cost:  0.08659811
j / n_batches: 260 / 410 cost:  0.08807735
j / n_batches: 270 / 410 cost:  0.08140585
j / n_batches: 280 / 410 cost:  0.083291486
j / n_batches: 290 / 410 cost:  0.084010296
j / n_batches: 300 / 410 cost:  0.083979346
j / n_batches: 310 / 410 cost:  0.08508629
j / n_batches: 320 / 410 cost:  0.08418372
j / n_batches: 330 / 410 cost:  0.08443065
j / n_batches: 340 / 410 cost:  0.08497323
j / n_batches: 350 / 410 cost:  0.08727572
j / n_batches: 360 / 410 cost:  0.085209474
j / n_batches: 370 / 410 cost:  0.08593008
j / n_batches: 380 / 410 cost:  0.085833095
j / n_batches: 390 / 410 cost:  0.08245342
j / n_batches: 400 / 410 cost:  0.08636347
Epoch:  6
j / n_batches: 0 / 410 cost:  0.08486315
j / n_batches: 10 / 410 cost:  0.083238035
j / n_batches: 20 / 410 cost:  0.08666235
j / n_batches: 30 / 410 cost:  0.08417287
j / n_batches: 40 / 410 cost:  0.084864065
j / n_batches: 50 / 410 cost:  0.082460426
j / n_batches: 60 / 410 cost:  0.086855754
j / n_batches: 70 / 410 cost:  0.08686972
j / n_batches: 80 / 410 cost:  0.08710295
j / n_batches: 90 / 410 cost:  0.08576269
j / n_batches: 100 / 410 cost:  0.08901186
j / n_batches: 110 / 410 cost:  0.084880784
j / n_batches: 120 / 410 cost:  0.09023496
j / n_batches: 130 / 410 cost:  0.08608874
j / n_batches: 140 / 410 cost:  0.085938185
j / n_batches: 150 / 410 cost:  0.08355316
j / n_batches: 160 / 410 cost:  0.085553005
j / n_batches: 170 / 410 cost:  0.08575877
j / n_batches: 180 / 410 cost:  0.08589571
j / n_batches: 190 / 410 cost:  0.085528344
j / n_batches: 200 / 410 cost:  0.084487416
j / n_batches: 210 / 410 cost:  0.08365902
j / n_batches: 220 / 410 cost:  0.08447495
j / n_batches: 230 / 410 cost:  0.08904719
j / n_batches: 240 / 410 cost:  0.085248634
j / n_batches: 250 / 410 cost:  0.08174812
j / n_batches: 260 / 410 cost:  0.0870948
j / n_batches: 270 / 410 cost:  0.08702458
j / n_batches: 280 / 410 cost:  0.08838867
j / n_batches: 290 / 410 cost:  0.08372959
j / n_batches: 300 / 410 cost:  0.08746541
j / n_batches: 310 / 410 cost:  0.08566536
j / n_batches: 320 / 410 cost:  0.083481185
j / n_batches: 330 / 410 cost:  0.08751248
j / n_batches: 340 / 410 cost:  0.08005118
j / n_batches: 350 / 410 cost:  0.08531479
j / n_batches: 360 / 410 cost:  0.08659164
j / n_batches: 370 / 410 cost:  0.08428435
j / n_batches: 380 / 410 cost:  0.0868164
j / n_batches: 390 / 410 cost:  0.08415032
j / n_batches: 400 / 410 cost:  0.085515335
Epoch:  7
j / n_batches: 0 / 410 cost:  0.08555791
j / n_batches: 10 / 410 cost:  0.08493644
j / n_batches: 20 / 410 cost:  0.083911896
j / n_batches: 30 / 410 cost:  0.08824175
j / n_batches: 40 / 410 cost:  0.085073814
j / n_batches: 50 / 410 cost:  0.087315485
j / n_batches: 60 / 410 cost:  0.08460724
j / n_batches: 70 / 410 cost:  0.08805971
j / n_batches: 80 / 410 cost:  0.08519505
j / n_batches: 90 / 410 cost:  0.08580028
j / n_batches: 100 / 410 cost:  0.0856415
j / n_batches: 110 / 410 cost:  0.08110774
j / n_batches: 120 / 410 cost:  0.08543504
j / n_batches: 130 / 410 cost:  0.09055285
j / n_batches: 140 / 410 cost:  0.085615024
j / n_batches: 150 / 410 cost:  0.08445757
j / n_batches: 160 / 410 cost:  0.083518304
j / n_batches: 170 / 410 cost:  0.083656706
j / n_batches: 180 / 410 cost:  0.08527048
j / n_batches: 190 / 410 cost:  0.08005291
j / n_batches: 200 / 410 cost:  0.08491557
j / n_batches: 210 / 410 cost:  0.082669094
j / n_batches: 220 / 410 cost:  0.08303942
j / n_batches: 230 / 410 cost:  0.08401001
j / n_batches: 240 / 410 cost:  0.08153374
j / n_batches: 250 / 410 cost:  0.08316496
j / n_batches: 260 / 410 cost:  0.089486465
j / n_batches: 270 / 410 cost:  0.08286301
j / n_batches: 280 / 410 cost:  0.08224556
j / n_batches: 290 / 410 cost:  0.08629742
j / n_batches: 300 / 410 cost:  0.085196815
j / n_batches: 310 / 410 cost:  0.08584966
j / n_batches: 320 / 410 cost:  0.08377248
j / n_batches: 330 / 410 cost:  0.08257979
j / n_batches: 340 / 410 cost:  0.08709627
j / n_batches: 350 / 410 cost:  0.08119677
j / n_batches: 360 / 410 cost:  0.07997007
j / n_batches: 370 / 410 cost:  0.08359154
j / n_batches: 380 / 410 cost:  0.08871019
j / n_batches: 390 / 410 cost:  0.08729488
j / n_batches: 400 / 410 cost:  0.08604878
Epoch:  8
j / n_batches: 0 / 410 cost:  0.08325234
j / n_batches: 10 / 410 cost:  0.08475158
j / n_batches: 20 / 410 cost:  0.082865104
j / n_batches: 30 / 410 cost:  0.08358227
j / n_batches: 40 / 410 cost:  0.08492126
j / n_batches: 50 / 410 cost:  0.08219543
j / n_batches: 60 / 410 cost:  0.08346773
j / n_batches: 70 / 410 cost:  0.083429195
j / n_batches: 80 / 410 cost:  0.08594631
j / n_batches: 90 / 410 cost:  0.08207984
j / n_batches: 100 / 410 cost:  0.08901368
j / n_batches: 110 / 410 cost:  0.08323219
j / n_batches: 120 / 410 cost:  0.08595456
j / n_batches: 130 / 410 cost:  0.0834731
j / n_batches: 140 / 410 cost:  0.086170256
j / n_batches: 150 / 410 cost:  0.084630564
j / n_batches: 160 / 410 cost:  0.081865944
j / n_batches: 170 / 410 cost:  0.09389543
j / n_batches: 180 / 410 cost:  0.08273296
j / n_batches: 190 / 410 cost:  0.08409217
j / n_batches: 200 / 410 cost:  0.08055624
j / n_batches: 210 / 410 cost:  0.080803476
j / n_batches: 220 / 410 cost:  0.08488298
j / n_batches: 230 / 410 cost:  0.08479639
j / n_batches: 240 / 410 cost:  0.08675831
j / n_batches: 250 / 410 cost:  0.089107364
j / n_batches: 260 / 410 cost:  0.08381842
j / n_batches: 270 / 410 cost:  0.08657514
j / n_batches: 280 / 410 cost:  0.08772018
j / n_batches: 290 / 410 cost:  0.07841797
j / n_batches: 300 / 410 cost:  0.08195477
j / n_batches: 310 / 410 cost:  0.08709426
j / n_batches: 320 / 410 cost:  0.08404292
j / n_batches: 330 / 410 cost:  0.0867257
j / n_batches: 340 / 410 cost:  0.07821198
j / n_batches: 350 / 410 cost:  0.08977814
j / n_batches: 360 / 410 cost:  0.08664142
j / n_batches: 370 / 410 cost:  0.08540241
j / n_batches: 380 / 410 cost:  0.08580899
j / n_batches: 390 / 410 cost:  0.081312455
j / n_batches: 400 / 410 cost:  0.087394185
Epoch:  9
j / n_batches: 0 / 410 cost:  0.08478356
j / n_batches: 10 / 410 cost:  0.08334903
j / n_batches: 20 / 410 cost:  0.08266941
j / n_batches: 30 / 410 cost:  0.088921785
j / n_batches: 40 / 410 cost:  0.08443197
j / n_batches: 50 / 410 cost:  0.08502948
j / n_batches: 60 / 410 cost:  0.082008444
j / n_batches: 70 / 410 cost:  0.08698873
j / n_batches: 80 / 410 cost:  0.08289124
j / n_batches: 90 / 410 cost:  0.085048884
j / n_batches: 100 / 410 cost:  0.08591306
j / n_batches: 110 / 410 cost:  0.08098228
j / n_batches: 120 / 410 cost:  0.08369001
j / n_batches: 130 / 410 cost:  0.08448028
j / n_batches: 140 / 410 cost:  0.08361733
j / n_batches: 150 / 410 cost:  0.08631721
j / n_batches: 160 / 410 cost:  0.08376367
j / n_batches: 170 / 410 cost:  0.084871076
j / n_batches: 180 / 410 cost:  0.08669336
j / n_batches: 190 / 410 cost:  0.0826638
j / n_batches: 200 / 410 cost:  0.087354675
j / n_batches: 210 / 410 cost:  0.08289438
j / n_batches: 220 / 410 cost:  0.08727235
j / n_batches: 230 / 410 cost:  0.08363863
j / n_batches: 240 / 410 cost:  0.08719861
j / n_batches: 250 / 410 cost:  0.08377235
j / n_batches: 260 / 410 cost:  0.08066959
j / n_batches: 270 / 410 cost:  0.08510112
j / n_batches: 280 / 410 cost:  0.08373716
j / n_batches: 290 / 410 cost:  0.08264735
j / n_batches: 300 / 410 cost:  0.085768305
j / n_batches: 310 / 410 cost:  0.083548754
j / n_batches: 320 / 410 cost:  0.08595308
j / n_batches: 330 / 410 cost:  0.081421226
j / n_batches: 340 / 410 cost:  0.08293149
j / n_batches: 350 / 410 cost:  0.08700574
j / n_batches: 360 / 410 cost:  0.08959815
j / n_batches: 370 / 410 cost:  0.08630945
j / n_batches: 380 / 410 cost:  0.08493046
j / n_batches: 390 / 410 cost:  0.08886025
j / n_batches: 400 / 410 cost:  0.08588381